#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
bool cmp(int a,int b){
    return a>b;
}
bool flag[101]={false};
int main(){
    //freopen("in.txt","r",stdin);
    int N;
    scanf("%d",&N);
    int a[N];
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
        int tmp=a[i];
        if(flag[tmp]==true){continue;}
        while(tmp!=1){
            if(tmp%2==0){tmp=tmp>>1;}
            else{tmp=(tmp*3+1)>>1;}
          	if(tmp>100)continue;
            if(flag[tmp]==true){break;}
            flag[tmp]=true;
        }
    }
    vector<int> ans;
    for(int i=0;i<N;i++){
        if(flag[a[i]]==false){
            ans.push_back(a[i]);
        }
    }
    sort(ans.begin(),ans.end(),cmp);
    printf("%d",ans[0]);
    for(int i=1;i<ans.size();i++){
        printf(" %d",ans[i]);
    }

}
